package com.example.demo.controller;

import com.example.demo.annotation.AutoIdempotent;
import com.example.demo.service.TokenService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2021/1/30 20:24
 */
@RestController
public class BusinessController
{
    @Autowired
    private TokenService tokenService;

    @PostMapping("/get/token")
    public String getToken()
    {
        String token = tokenService.createToken();
        if (StringUtils.isNotEmpty(token))
        {
            return token;
        }
        return StringUtils.EMPTY;
    }

    @AutoIdempotent
    @GetMapping("/test/Idempotence")
    public String testIdempotence(HttpServletRequest req)
    {
        return "aaa！";
    }
}
